package com.taorenqi.business.fragment.main;


import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.widget.Toolbar;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.sunfusheng.marqueeview.MarqueeView;
import com.taorenqi.business.R;
import com.taorenqi.business.event.SwitchTabEvent;
import com.taorenqi.business.fragment.base.BaseMainFragment;
import com.taorenqi.business.widget.statusview.StatusUtils;
import com.taorenqi.business.widget.statusview.StatusView;

import org.greenrobot.eventbus.EventBus;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * A simple {@link Fragment} subclass.
 */
public class HomeFragment extends BaseMainFragment {


    @Bind(R.id.status_view)
    StatusView mStatusView;
    @Bind(R.id.toolbar)
    Toolbar toolbar;
    @Bind(R.id.home_container)
    LinearLayout homeContainer;
    @Bind(R.id.toolbar_title)
    TextView toolbarTitle;
    @Bind(R.id.iv_loudspeaker)
    ImageView ivLoudspeaker;
    @Bind(R.id.marqueeView)
    MarqueeView mMarqueeView;
    @Bind(R.id.marqueeView2)
    MarqueeView mMarqueeView2;
    @Bind(R.id.home_ll_comment)
    LinearLayout homeLlComment;
    @Bind(R.id.home_fabu)
    TextView homeFabu;
    @Bind(R.id.home_tiyan)
    TextView homeTiyan;
    @Bind(R.id.home_personal)
    TextView homePersonal;

    public static HomeFragment newInstance() {
        // Required empty public constructor
        HomeFragment fragment = new HomeFragment();
        Bundle bundle = new Bundle();
        fragment.setArguments(bundle);
        return fragment;
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View view = inflater.inflate(R.layout.fragment_home, container, false);
        ButterKnife.bind(this, view);
        StatusUtils.setLayoutFullScreen(_mActivity);
        setToolbarStatusBarAlpha(0);
        initToolbar();
        initMarqueeView();
        return view;
    }

    private void initMarqueeView() {
        List<String> info = new ArrayList<>();
        info.add("迎新春，过大年，91陪你全家欢！");
        info.add("91人气升级通知。");

        List<String> info2 = new ArrayList<>();
        info2.add("91人气升级通知。");
        info2.add("迎新春，过大年，91陪你全家欢！");

        mMarqueeView.startWithList(info);
        mMarqueeView2.startWithList(info2);
    }

    private void initToolbar() {
        toolbarTitle.setText("首页");
    }


    private void setToolbarStatusBarAlpha(int alpha) {
        mStatusView.getBackground().mutate().setAlpha(alpha);
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        ButterKnife.unbind(this);
    }

    @OnClick({R.id.home_fabu, R.id.home_tiyan, R.id.home_personal})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.home_fabu:
                break;
            case R.id.home_tiyan:
                break;
            case R.id.home_personal:
                EventBus.getDefault().post(new SwitchTabEvent());
                break;
        }
    }
}
